package neusoft.yuejian_11.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import java.util.List;

import neusoft.yuejian_11.adapter.TrainListAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.TrainBean;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.TrainModel;
import neusoft.yuejian_11.R;

//培训菜鸟类型(已改）
public class TrainCainiaoActivity extends BaseActivity  implements RetrofitListener {
    private RecyclerView recyclerView;
    private TrainListAdapter trainListAdapter;
    private ImageButton imageButtonBack;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_traincainiao);
        initView();
        initData();
    }

    private void initData() {
        TrainModel trainModel = new TrainModel();
        trainModel.getCainiaoTrains(this);
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public void onSuccess(Object o, int flag) {
                List<TrainBean> trainBean=(List<TrainBean>)o;
                trainListAdapter = new TrainListAdapter(TrainCainiaoActivity.this,trainBean);
                LinearLayoutManager layoutManager = new LinearLayoutManager(TrainCainiaoActivity.this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(layoutManager);
                recyclerView.setAdapter(trainListAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    public void onFail() {

    }
}
